home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
157_01
/
qed
< prev
next >
Wrap
Text File
|
1987-10-10
|
14KB
|
628 lines
/* VERSION 0021 (DATE: 28/04/87) (TIME: 16:59) */
/*
e (qed) screen editor
(C) G. Nigel Gilbert, MICROLOGY, 1981
licensed for private non-profitmaking use 1983
August-December 1981
Modified: Aug-Dec 1984: BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
March 1985: BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
FILE: qed
FUNCTIONS: main, initialise, edit, finish, seldisk
PURPOSE: initialise; process commands;
*/
#include "qed.h"
#define VERNO 0x30 /* get MSDOS version number */
main(argc,argv)
int argc;
char **argv;
{
int argn;
int i;
char *dig;
/**************************Default option settings***************************/
initjmp=1; /*jmp to line 1*/
autoin=YES; /*auto indent [YES/NO]*/
backup=YES; /*make ".BAK" file [YES/NO]*/
readall=YES; /*read as much text as possible up to memory*/
trail=NO; /*don't strip trailing blanks [YES/NO]*/
helpon=NO; /*start with help menu on [YES/NO]*/
expert=YES; /*brief prompts [YES/NO]*/
tabwidth=4; /*tab stops every n cols [number]*/
displaypos=YES; /*display line:column at top of screen*/
blockscroll=NO; /*don't scroll whole page, just current line*/
pagingdisk=0; /*create buffer file on this disk -
set to either 0 (for currently logged-in disk)
or to desired disk letter (eg 'B') */
wboot=YES; /*do a warm boot at end of edit [YES/NO]*/
defext[0]='\0'; /* default extension */
#if WWRAP
rtmarg=LLIM; /* right margin*/
#endif
#if VRSNNUM
version=YES; /* change version num on save*/
*date='\0';
*time='\0';
#endif
/***********************End of default option settings***********************/
inbufp=0;
if((_os(VERNO,0) & 0x00ff) < 2) {
puts("Must use MSDOS vers 2.x with 'qed'");
exit(0);
}
filename[0]=name[0]='\0';
argn=0;
while (++argn < argc)
if (*argv[argn] == '-') {
dig=argv[argn]+1;
switch(toupper(*dig)) {
case 'J' :
initjmp = atoi((argv[argn]+2));
break;
case 'A' :
autoin=!autoin;
break;
case 'B' :
backup=!backup;
break;
case 'L' :
displaypos=!displaypos;
break;
case 'H' :
blockscroll=!blockscroll;
break;
case 'R' :
readall=!readall;
break;
#if WWRAP
case 'M' :
rtmarg=0;
rtmarg=atoi((argv[argn]+2));
if (rtmarg < LLIM) {
trail=YES;
autoin=NO;
}
break;
#endif
case 'T' :
tabwidth=0;
while (*++dig) tabwidth=tabwidth*10+*dig-'0';
break;
case 'S' :
trail=!trail;
break;
#if VRSNNUM
case 'U' :
version = !version;
break;
#endif
case 'V' :
helpon=!helpon;
break;
case 'E' :
expert=!expert;
break;
case 'X' :
wboot=!wboot;
break;
case 'D' :
pagingdisk=toupper(*(dig+1));
if (pagingdisk >= 'A' && pagingdisk <= 'P') break;
default :
putstr("Illegal option: ");
putstr(argv[argn]);
exit();
}
}
else strcpy(filename[0] ? name : filename,argv[argn]);
ans[0]=patt[0]=changeto[0]=opts[0]='\0';
keytranslate();
do {
initialise();
edit();
}
while (YES);
}
initialise()
{
int i,warn;
cursorx=charn=offset=lastoff=from=to=0;
cursory=topline=lastread=lastl=findir=jmpto=1;
changed=isdim=replace=repeat=blocking=warn=blankedmess=NO;
pfirst=-100;
goteof=YES;
errmess=NULL;
curdsk=_os(CURDSK);
bakpath[0]='B';
bakpath[1]=':';
bakpath[2]='\\';
bakpath[3]='\0';
initvm();
text[0]='\0';
cline=1;
altered=YES;
puttext();
setstatusname();
if (filename[0]) {
putclr();
gotoxy(8,11);
putstr("qed screen editor version ");
putstr(VERSION);
gotoxy(12,12);
putstr("MICROLOGY 1983 and JWH 1985");
gotoxy(12,13);
terminal();
while (opentext(filename) == FAIL) {
if (opentext(strcat(filename,defext)) == FAIL) {
askforfile();
if (!filename[0]) goto newfile;
}
}
lastl=UNKNOWN;
lastread=0;
goteof=NO;
if (name[0]) {
strcpy(filename,name);
name[0]='\0';
}
}
newfile: errmess=NULL;
format(filename);
/*read as much text to fill memory or end of file*/
if (readall)
for (i=1;(!(usage[slotsinmem-1]) && (!(goteof)));i+=100)
readtext(i);
setstatusname();
gettext(1);
putclr();
if (helpon) dohelp();
if (initjmp>2) { /* (2-1) is a bad jump from line 1 */
jumpline(initjmp-cline); /* not possible to do init jump to 2*/
initjmp=0;
putstatusline(cline);
}
else
putpage();
}
edit() /*command processor*/
{
char c;
char oldcrx,inc;
int to;
setjmp(0);
while (YES) {
goodline=cline;
if ((expert) && (!blankedmess)) xmessoff();
else if (!blankedmess) unmess();
putlineno(cline);
resetcursor();
c=getkey();
if (errmess != NULL) {
errmess=NULL;
putstatusline(cline);
}
switch(c) {
case DOWNKEY :
moveline(1);
break;
case UPKEY :
moveline(-1);
break;
case LEFTKEY :
movechar(-1);
break;
case RIGHTKEY :
movechar(1);
break;
case LEFTWKEY :
moveword(-1);
break;
case RIGHTWKEY :
moveword(1);
break;
case BOLKEY :
sync(0);
break;
case EOLKEY :
sync(strlen(text));
break;
case UPPAGE :
movepage(-1);
break;
case DOWNPAGE :
movepage(0);
break;
case HOMEKEY :
if (jumpline(lastl-cline)) sync(strlen(text));
break;
case BOFKEY :
if (jumpline(1-cline)) sync(0);
break;
case DELLEFT :
changed=YES;
deletechar(-1);
break;
case DELRIGHT :
deletechar(0);
changed=YES;
break;
case DELLNKEY :
changed=YES;
strcpy(textb,text); /*save for undelete line*/
text[0]='\0';
crdelete((cline == lastl ? -1 : 0));
break;
case DELWDKEY :
changed=YES;
deleteword();
break;
case JUMPKEY :
if (expert) xprtmess("J ? ");
else putmess("Jump ([+/-]n,RET=crnt) ? ");
scans(ans,8);
if (!*ans) jmpto = cline;
else
calcjmp();
if (expert) xmessoff();
break;
case TOPSCRKEY :
moveline((topline-cursory));
break;
case BOTSCRKEY :
moveline((SHEIGHT-cursory));
break;
case REPKEY :
repeat=YES;
dofindrep(1,1);
repeat=NO;
break;
case BLOCKKEY :
switch (to=blockops()) {
case YES : return;
break;
case 'x' :
case 'q' : if (finish(to)==YES) return;
break;
case 'r' :
if (expert) xprtmess("Read file? ");
else putmess("File to read? ");
scans(name,FILELEN);
if (*(name)) {
readfile(name);
putpage();
changed=YES;
}
break;
}
break;
case SCRLDNKEY :
/* original: slow but sure
oldcrx = cursorx;
to = plast-cline;
moveline(to);
inc=( (moveline(1)==YES) ? 1 : 0);
cursorx = oldcrx;
moveline(((cline-to)<=pfirst) ? (topline-cursory) : (-to - inc));
*/
/* new: 29.viii.86*/
if(cursory==topline) puttext();
if (plast>=(pfirst+2)) {
linedelete(topline);
inc = plast-pfirst;
if (plast<lastl) {
getline(++plast);
putline(plast,
(inc<(SHEIGHT-topline)) ? (inc) : SHEIGHT);
}
pfirst++;
if (cursory==topline) gettext(pfirst);
cursorx=adjustc(cursorx);
gotoxy(cursorx, (cursory -= cursory>topline ? 1 : 0));
}
break;
case UNDELINE :
/* helpon via kontext key
if (helpon) {
helpon=NO;
unmess();
}
else {
helpon=YES;
dohelp();
}
*/
puttext();
cline=inject(cline,textb);
if (cursory>=SHEIGHT) {
linedelete(topline);
gotoxy(0,cursory);
gettext(cline);
putline(cline,cursory);
plast++;
pfirst++;
}
else {
gotoxy(0,++cursory);
insertline();
gettext(cline);
putline(cline,cursory);
if ((plast-pfirst) < SHEIGHT-topline) plast++;
}
break;
case CR :
changed=YES;
crinsert(0);
break;
case CRSTILL :
changed=YES;
crinsert(-1);
break;
case SCRLUPKEY :
/* original: save current cursorx
oldcrx = cursorx;
to = toplin